package com.augurit.smartform.converter;

import com.augurit.common.entity.SysMetaTable;
import com.augurit.smartform.database.Table;

public class FormConverter {
	public static Table convertToTable(SysMetaTable sysMetaTable){
		Table table=null;
		if(sysMetaTable!=null){
			table=new Table();
			table.setPageId(sysMetaTable.getPageId());
			table.setCategory(sysMetaTable.getCategory());
			table.setCreateTime(sysMetaTable.getCreateTime());
			table.setVersion(sysMetaTable.getVersion());
			
			table.setName(sysMetaTable.getFormName());
			table.setCreator(sysMetaTable.getOwner());
			table.setCnName(sysMetaTable.getTableChineseComments());
			table.setDescription(sysMetaTable.getMemo());
			Table parent=new Table();
			parent.setName(sysMetaTable.getParentFormName());
			parent.setFullName(sysMetaTable.getParentTableName());
			table.setParent(parent);
			table.setSourceXmlStr(sysMetaTable.getRawXml());
			table.setFullName(sysMetaTable.getTableName());
			if("Y".equalsIgnoreCase(sysMetaTable.getSmartform())){
				table.setSmartform(Boolean.TRUE);
			}else if("N".equalsIgnoreCase(sysMetaTable.getSmartform())){
				table.setSmartform(Boolean.FALSE);
			}
		}
		return table;
	}
	
	public static SysMetaTable convertToSysMetaTable(Table table){
		SysMetaTable sysMetaTable=null;
		if(table!=null){
			sysMetaTable=new SysMetaTable();
			sysMetaTable.setPageId(table.getPageId());
			sysMetaTable.setCategory(table.getCategory());
			sysMetaTable.setCreateTime(table.getCreateTime());
			sysMetaTable.setVersion(table.getVersion());
			
			sysMetaTable.setFormName(table.getName());
			sysMetaTable.setOwner(table.getCreator());
			sysMetaTable.setTableChineseComments(table.getCnName());
			sysMetaTable.setMemo(table.getDescription());
			if(table.getParent()!=null){
				Table parent=table.getParent();
				sysMetaTable.setParentFormName(parent.getName());
				sysMetaTable.setParentTableName(parent.getFullName());
			}
			sysMetaTable.setRawXml(table.getSourceXmlStr());
			sysMetaTable.setTableName(table.getFullName());
			if(table.isSmartform()){
				sysMetaTable.setSmartform("Y");
			}else{
				sysMetaTable.setSmartform("N");
			}
		}
		return sysMetaTable;
	}
	
	public static void convertToSysMetaTable(Table table,SysMetaTable sysMetaTable){
		if(table!=null&&sysMetaTable!=null){
			sysMetaTable.setPageId(table.getPageId());
			sysMetaTable.setCategory(table.getCategory());
			sysMetaTable.setCreateTime(table.getCreateTime());
			sysMetaTable.setVersion(table.getVersion());
			
			sysMetaTable.setFormName(table.getName());
			sysMetaTable.setOwner(table.getCreator());
			sysMetaTable.setTableChineseComments(table.getCnName());
			sysMetaTable.setMemo(table.getDescription());
			if(table.getParent()!=null){
				Table parent=table.getParent();
				sysMetaTable.setParentFormName(parent.getName());
				sysMetaTable.setParentTableName(parent.getFullName());
			}
			sysMetaTable.setRawXml(table.getSourceXmlStr());
			sysMetaTable.setTableName(table.getFullName());
			if(table.isSmartform()){
				sysMetaTable.setSmartform("Y");
			}else{
				sysMetaTable.setSmartform("N");
			}
		}
	}
}
